<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php use_helper('Tagcloud') ?>

<form action="<?php echo url_for('campaign/' . ($form->getObject()->isNew() ? 'create' : 'update') . (!$form->getObject()->isNew() ? '?campaign_id=' . $form->getObject()->getCampaignId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
    <?php if (!$form->getObject()->isNew()): ?>
        <input type="hidden" name="sf_method" value="put" />
    <?php endif; ?>
        <table>
            <tfoot>
                <tr>
                    <td colspan="2">
                    <?php echo $form->renderHiddenFields(false) ?>
                    &nbsp;<a href="<?php echo url_for('campaign/index') ?>">Back to list</a>
                    <?php if (!$form->getObject()->isNew()): ?>
                        &nbsp;<?php echo link_to('Delete', 'campaign/delete?campaign_id=' . $form->getObject()->getCampaignId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
                    <?php endif; ?>
                        <input type="submit" value="Save" />
                    </td>
                </tr>
            </tfoot>
            <tbody>
            <?php echo $form->renderGlobalErrors() ?>
                        <tr>
                            <th><?php echo $form['name']->renderLabel() ?></th>
                            <td>
                    <?php echo $form['name']->renderError() ?>
                    <?php echo $form['name'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['description']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['description']->renderError() ?>
                    <?php echo $form['description'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['recipients_filter']->renderLabel() ?>
                        <br/><br/>
                        <span class="hint"> use expressions like <br/>
                            "<i>[recipientfield1] = 'value' <br/>
                                AND [racipientfield2] = 2</i>"   </span>

                    </th>
                    <td>
                    <?php echo $form['recipients_filter']->renderError() ?>
                    <?php echo $form['recipients_filter'] ?>
                        <a onclick="{
                                var data = $.get('<?php echo url_for('@countrecipientfilter') . '?recipientsfilter='; ?>' + $('#campaign_recipients_filter').val(),function(data){
                                    $('.jquer_log').text('');
                                    $( '#recipient_count' ).html(data ) ;
                                    $( '#recipient_count' ).effect('highlight');
                                });
                            }
                           ">Check Filter</a>
                        <div id="recipient_count" class="inline_div"></div>
                    </td>
                </tr>
                <tr>
                    <th><label>Available Tags</label></th>
                    <td>
                    <?php
                        TagcloudHelper::showCloud($sf_data->getRaw('tags'));
                    ?>
                    </td>
                </tr>


                <tr>
                    <th>
                    <?php echo $form['tags_filter']->renderLabel() ?><br/><br/>
                        <span class="hint"> use expressions like <br/>
                            "<i>tag_[name1] > 0 <br/>
                                AND tag_[name2] < 2</i>"   </span>
                    </th>
                    <td>
                    <?php echo $form['tags_filter']->renderError() ?>
                    <?php echo $form['tags_filter'] ?>
                        <a onclick="{
                            var data = $.get('<?php echo url_for('@countrecipientfilter') . '?tagsfilter='; ?>' + $('#campaign_tags_filter').val(),function(data){
                                $('.jquer_log').text('');
                                $( '#tags_recipient_count' ).html(data ) ;
                                $( '#tags_recipient_count' ).effect('highlight');
                            });
                        }
                           ">Check Filter</a>
                        <div id="tags_recipient_count" class="inline_div"></div>


                    </td>
                </tr>
                <tr>
                    <th>
                        <label>Test both filters:</label>
                    </th>
                    <td>
                        <a onclick="{
                        var data = $.get('<?php echo url_for('@countrecipientfilter') . '?recipientsfilter='; ?>'
                            + $('#campaign_recipients_filter').val() + '&tagsfilter=' + $('#campaign_tags_filter').val(),function(data){
                            $('.jquer_log').text('');
                            $( '#total_recipient_count' ).html(data ) ;
                            $( '#total_recipient_count' ).effect('highlight');
                        });
                    }
                           ">Check Filter</a>
                        <div id="total_recipient_count" class="inline_div"></div><div class="jquer_log"></div>
                        <script type="text/javascript">
                            $('.jquer_log').ajaxError(function() {
                                $(this).text('Wrong filter');
                            });
                        </script>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['continuous']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['continuous']->renderError() ?>
                    <?php echo $form['continuous'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['start_date']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['start_date']->renderError() ?>
                    <?php echo $form['start_date'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['stop_date']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['stop_date']->renderError() ?>
                    <?php echo $form['stop_date'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['template_id']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['template_id']->renderError() ?>
                    <?php echo $form['template_id'] ?>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['status']->renderLabel() ?></th>
                    <td>
                    <?php echo $form['status']->renderError() ?>
                    <?php echo $form['status'] ?>
                </td>
            </tr>
        </tbody>
    </table>
</form>
